package com.teatrace.model.base;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.teatrace.model.produce.MaterialPackage;

@Entity
public class Storage {

	@Id
	@Column(name="storage_id")
	private int id;//storage_id
	
	private String name;
	
	private String capacity;//容量
	
	@Column(name="residual_capacity")
	private String residualCapacity;//剩余容量residual_capacity
	
	private String description;

	private boolean deleted;
	
	//@ManyToOne(targetEntity=StorageType.class)
	//@JoinColumn(name="type")
	//private StorageType storageType;//仓库类型
	
	
	@OneToMany(
			cascade = { CascadeType.ALL},
			mappedBy ="storage",
			fetch=FetchType.EAGER
	)
	private Set<MaterialPackage> materialPackageSet = new HashSet<MaterialPackage>();
	
	public boolean getDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getCapacity() {
		return capacity;
	}

	public void setCapacity(String capacity) {
		this.capacity = capacity;
	}

	public String getResidualCapacity() {
		return residualCapacity;
	}

	public void setResidualCapacity(String residualCapacity) {
		this.residualCapacity = residualCapacity;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

//	public void setStorageType(StorageType storageType) {
//		this.storageType = storageType;
//	}
//
//	public StorageType getStorageType() {
//		return storageType;
//	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}
	
	public void addMaterialPackage(MaterialPackage materialPackage){
		if(!materialPackageSet.contains(materialPackage)){
			materialPackage.setStorage(this);
			this.materialPackageSet.add(materialPackage);
		}
	}
	
	public void removeMaterialPackage(MaterialPackage materialPackage){
		materialPackage.setStorage(null);
		this.materialPackageSet.remove(materialPackage);
	}
}
